import request from '@/axios'
import { CreateTableTreeType, CreateTableType } from './types'

export const getTreeApi = (code: string): Promise<IResponse<CreateTableTreeType[]>> => {
  return request.get({ url: '/dbms-server/create/table/tree', params: { code } })
}

export const getJsonDataApi = (code: string) => {
  return request.get({ url: '/dbms-server/create/table/getJsonData', params: { code } })
}

export const addApi = (data: CreateTableType): Promise<IResponse<CreateTableType>> => {
  return request.post({ url: '/dbms-server/create/table/add', data })
}

export const updateApi = (data: CreateTableType) => {
  return request.put({
    url: '/dbms-server/create/table/update',
    data
  })
}

export const updateJsonDataApi = (code: string, jsonData: string, formOption: string) => {
  return request.put({
    url: '/dbms-server/create/table/updateJsonData',
    data: { code, jsonData, formOption }
  })
}

export const moveApi = (code: string, parentCode: string) => {
  return request.put({ url: '/dbms-server/create/table/move', data: { code, parentCode } })
}

export const deleteApi = (code: string) => {
  return request.delete({ url: '/dbms-server/create/table/delete', params: { code } })
}
